package ide.modelo;

import java.util.*;

public class Conversor {

	@SuppressWarnings("serial")
	private static final Hashtable<String,String> instrucciones=new Hashtable<String,String>() {{
		put("carmem","1");
		put("carinm","2");
		put("alm","3");
		put("cop","4");
		put("suma2","5");
		put("sumpf","6");
		put("or","7");
		put("and","8");
		put("xor","9");
		put("rot","A");
		put("sal","B");
		put("parar","C");		
		}};

	@SuppressWarnings("serial")
	private static final Hashtable<String,String> registros=new Hashtable<String,String>() {{
		put("r0","0");
		put("r1","1");
		put("r2","2");
		put("r3","3");
		put("r4","4");
		put("r5","5");
		put("r6","6");
		put("r7","7");
		put("r8","8");
		put("r9","9");
		put("r10","A");
		put("r11","B");
		put("r12","C");
		put("r13","D");
		put("r14","E");
		put("r15","F");		
		}};		
		
		@SuppressWarnings("serial")
		private static final Hashtable<String,String> caracteres=new Hashtable<String,String>() {{
			put("0","0000");
			put("1","0001");
			put("2","0010");
			put("3","0011");
			put("4","0100");
			put("5","0101");
			put("6","0110");
			put("7","0111");
			put("8","1000");
			put("9","1001");
			put("A","1010");
			put("B","1011");
			put("C","1100");
			put("D","1101");
			put("E","1110");
			put("F","1111");		
			}};		
		
	public boolean esInstruccion(String entrada) {

		boolean salida = Conversor.instrucciones.containsKey(entrada);
		return salida;
	}

	public boolean esRegistro(String entrada) {

		boolean salida = Conversor.registros.containsKey(entrada);
		return salida;
	}
	
	public boolean esHexa(String entrada){
		
		boolean salida = Conversor.caracteres.containsKey(entrada);						
		return salida;
	}
	
	public String convertirHexaABinario(String entrada){
		
		String salida = Conversor.caracteres.get(entrada);
		if(salida==null){
			salida ="";
		}
		return salida;
	}	

	public String convertirEnsamAHexa(String entrada) {

		String salida = Conversor.instrucciones.get(entrada);
		if (salida == null){
			salida = Conversor.registros.get(entrada);		
		}
		if(salida==null){
			salida ="";
		}
		return salida;
	}
}